<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ include file="../session.jsp"%>
<!DOCTYPE html>
<html lang="ko">
  <head>
  	<%@ include file="../head.jsp"%>${alert}
  	<style>
  		.addon {
  			background-color: #ffffff;
  			border: 0px;
  		}
  	</style>
  <link rel="stylesheet" type="text/css" href="assets/css/lightbox.css" />
  </head>
  <body>
  	<%@ include file="../menu.jsp"%>
	<div class="container">
		<div class="page-header">
			<h2>이벤트 조회/수정</h2>
		</div>

		<form id="updateEvent" class="form-horizontal" role="form" method="post" action="updateEvent.do" enctype="multipart/form-data">
			<fieldset>
			
				<input type="hidden" name="id" value="${cmd.idAdminBoard}"/>
			
				<div class="form-group">
					<label for="isDisplay" class="col-md-2 control-label">상태</label>
					<div class="col-md-10">
						<c:choose>
							<c:when test="${cmd.isDisplay == 1}">
								<label class="radio-inline"><input type="radio" name="isDisplay" value="1" checked> 노출</label>
								<label class="radio-inline"><input type="radio" name="isDisplay" value="0"> 미노출</label>
							</c:when>
							<c:otherwise>
								<label class="radio-inline"><input type="radio" name="isDisplay" value="1"> 노출</label>
								<label class="radio-inline"><input type="radio" name="isDisplay" value="0" checked> 미노출</label>
							</c:otherwise>
						</c:choose>
					</div>
				</div>

				<div class="form-group">
					<label for="idEvent" class="col-md-2 control-label">이벤트 번호</label>
					<div class="col-md-10">
						<p class="form-control-static">${cmd.idAdminBoard}</p>
					</div>
				</div>

				<div class="form-group">
					<label for="boardTitle" class="col-md-2 control-label">이벤트명</label>
					<div class="col-md-10">
						<input type="text" class="form-control" name="boardTitle" value="${cmd.boardTitle}"/>
					</div>
				</div>

				<div class="form-group">
					<label for="brand" class="col-md-2 control-label">클라이언트</label>
					<div class="col-md-10">
						<select name="brand" class="form-control">
							<option>- 선택하세요 -</option>
							<c:forEach items="${brand}" var="brand">
								<option value="${brand.idBrand}" <c:if test="${brand.idBrand == cmd.idBrand}">selected</c:if>>${brand.brandTitle}</option>
							</c:forEach>
						</select>
					</div>
				</div>
				
				<div class="form-group">
					<label for="eventImg" class="col-md-2 control-label">이미지 <span class="text-danger">(640x360)</span></label>
					<div class="col-md-10">
						<div class="row">
							<div class="col-md-4">
								<p class="form-control-static">
									<a href="download.jsp?${image}" data-lightbox="roadtrip" title="${cmd.boardTitle}">
										<img src="download.jsp?${image}" class="img-thumbnail img-responsive"/>
									</a>
								</p>
							</div>
							<div class="col-md-8">
								<br/>
								<ul>
									<li>항번: ${image.idAttacheFile}</li>
									<li>원본 파일 이름: ${image.fileOrgName}</li>
									<li>파일 크기: ${image.fileSize}byte</li>
									<li>업로드된 파일 이름: ${image.fileSaveName}</li>
									<li>업로드된 폴더 경로: ${image.fileDir}</li>
									<li>파일 타입: ${image.fileType}</li>
								</ul>
								&nbsp;&nbsp;&nbsp;&nbsp;
								<button type="button" class="btn btn-sm" id="imgEdit">변경</button>
								<br/><br/>
								<div id="imgDiv"><input type="file" class="form-control" name="editImg"/></div>
							</div>
						</div>
					</div>
				</div>
				
				<div class="form-group">
					<label for="start_date" class="col-md-2 control-label">기간</label>
					<div class="col-md-10 input-group input-group-sm">
						<input type="datetime-local" class="form-control" name="start_date" 
						value="${fn:substring(cmd.start_date, 0, 4)}-${fn:substring(cmd.start_date, 4, 6)}-${fn:substring(cmd.start_date, 6, 8)}T${fn:substring(cmd.start_date, 8, 10)}:${fn:substring(cmd.start_date, 10, 12)}">
						<span class="input-group-addon addon">~</span>
						<input type="datetime-local" class="form-control" name="end_date" 
						value="${fn:substring(cmd.end_date, 0, 4)}-${fn:substring(cmd.end_date, 4, 6)}-${fn:substring(cmd.end_date, 6, 8)}T${fn:substring(cmd.end_date, 8, 10)}:${fn:substring(cmd.end_date, 10, 12)}">
					</div>
				</div>
				
				<div class="form-group">
					<label for="boardText" class="col-md-2 control-label">내용</label>
					<div class="col-md-10">
						<textarea id="boardText" name="boardText" class="form-control" rows="10">${cmd.boardText}</textarea>
					</div>
				</div>

				<div class="form-group">
					<label for="eventType" class="col-md-2 control-label">이벤트 구분</label>
					<div class="col-md-10">
						<select name="eventType" class="form-control">
							<option>- 선택하세요 -</option>
							<c:forEach items="${eventType}" var="type">
								<option value="${type.idCommon}" <c:if test="${type.idCommon == cmd.eventLinkType}">selected</c:if>>${type.commonText}</option>
							</c:forEach>
						</select>
					</div>
				</div>

				<div class="form-group">
					<label for="eventLinkCode" class="col-md-2 control-label">링크코드</label>
					<div class="col-md-10">
						<input type="text" class="form-control" name="eventLinkCode" value="${cmd.eventLinkCode}"/>
					</div>
				</div>

				<div class="form-group">
					<label for="countProduct" class="col-md-2 control-label">덧글수</label>
					<div class="col-md-10">
						<p class="form-control-static">
							<a href="#" onclick="window.open('eventComment.do?id=${cmd.idAdminBoard}', '', 'width=1000, height=600, scrollbars=yes, toolbar=no, menubar=no, status=no, location=no'); return false;">${cmd.comment_count}</a>
						</p>
					</div>
				</div>

				<div class="form-group">
					<div class="col-md-offset-2 col-md-10">
						<div class="row">
							<div class="col-md-6">
								<button type="submit" class="btn btn-primary btn-block">수정하기</button>
							</div>
							<div class="col-md-6">
								<button type="reset" class="btn btn-warning btn-block">다시작성</button>
							</div>
						</div>
					</div>
				</div>

			</fieldset>
		</form>
	</div>
	<!-- Javascript -->
	<script src="assets/js/jquery.js"></script>
	<script src="assets/js/bootstrap.min.js"></script>
	<script src="assets/js/lightbox-2.6.min.js"></script>
	<!-- 형식검사 클래스 참조 -->
	<script src="assets/js/string.js"></script>
	<script type="text/javascript">
		$(function() {
			$("#updateEvent").submit(function() {
				
				if (!$("input[name='isDisplay']").is(":checked")) {
					alert("노출상태를 선택해 주세요");
					$("input[name='isDisplay']").focus();
					return false;
				}
				
				if (!$("input[name='boardTitle']").val().isValue()) {
					alert("이벤트명을 입력하세요.");
					$("input[name='boardTitle']").focus();
					return false;
				}
				
				if ($("select[name='brand'] > option:selected").index() < 1) {
					alert("클라이언트를 선택하세요.");
					$("select[name='brand']").focus();
					return false;
				}
				
				if (!$("input[name='start_date']").val().isValue()) {
					alert("시작일을 입력하세요.");
					$("input[name='start_date']").focus();
					return false;
				}
				
				if (!$("input[name='end_date']").val().isValue()) {
					alert("종료일를 입력하세요.");
					$("input[name='end_date']").focus();
					return false;
				}
				
				if (!$("textarea[name='boardText']").val().isValue()) {
					alert("내용을 입력하세요.");
					$("textarea[name='boardText']").focus();
					return false;
				}
				
				if ($("select[name='eventType'] > option:selected").index() < 1) {
					alert("이벤트 구분을 선택하세요.");
					$("select[name='eventType']").focus();
					return false;
				}
				
				if (!$("input[name='eventLinkCode']").val().isValue()) {
					alert("링크코드를 입력하세요.");
					$("input[name='eventLinkCode']").focus();
					return false;
				}
				
				<c:forEach items="${imageList}" var="list">
					if (!$("input[name='sort${list.idAttacheFile}']").val().isValue()) {
						alert("이미지 순서는 공백이 될수 없습니다.");
						$("input[name='sort${list.idAttacheFile}']").focus();
						return false;
					}
				</c:forEach>
				
				if (!confirm("정말 수정하시겠습니까?")) {
					return false;
				}
			});
		});
	</script>
	<script>
		$(function() {
			$("#imgDiv").hide();
			
			$("#imgEdit").click(function() {
				$("input[name='editImg']").replaceWith($("input[name='editImg']").clone(true));
				$("#imgDiv").toggle();
			});
		});
	</script>
  </body>
</html>